Repository navigation
Conversation
When the buffer ran out before 21 bits, the last pass filled the remaining bits but still read buffer[i] with i at count or count+1. With a full buffer that is past the end of dma_buffer_copy. Only read the buffer for an index inside it. The bits check only ran for an index inside the buffer, so after the fill a second pass shifted by len - 1 with len 0. And when a transition had already taken bits past 21, the fill wrapped len so that bits came back to exactly 21 and the corrupt frame was decoded. Check bits first on every pass, so such a frame now gives INVALID_ERPM. Checked on the host against the old loop with 2 million generated frames, with ARM shift semantics for the old one: the results are the same except for those overshooting frames, and a full buffer of equal samples no longer reads buffer[23] of 22. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head This targeted fix looks correct. Moving the bits check first and reading the buffer only for in-range indices stops the F1 reversed decoder reading past dma_buffer_copy, and valid frames decode as before. Follow-up (not required for this PR)
A suggestion to reword the commit message was withdrawn: the old loop could accept an overshooting frame (a reproduced example decodes to 0x0000), so the message is accurate. |
Global Size Summary (Total Flash delta in bytes)Built from 4677ae3 rebased onto 32f5752
|
|
@andyp1per this looks correct to tridge and myself, but tridge thinks it really should be tested on hardware befoire merging. Do you have a suitable setup for that? The iofirmwares will need to be rebuilt with this change in it. |
Summary
Fix two problems in
bdshot_decode_telemetry_packet_f1(), the bidirectional DShot decode used on F1 IOMCUs:buffer[i]withiatcountorcount+1. With a full buffer that reads past the end ofdma_buffer_copy.len - 1withlen0. When a transition had already taken the bits past 21, the fill wrappedlenso that bits came back to exactly 21, and the corrupt frame was decoded.Read the buffer only for an index inside it, and check the bits on every pass, so an overshooting frame now gives
INVALID_ERPM.Found while answering a review question on #34647.
Classification & Testing (check all that apply and add your own)
Checked by a human programmer
Non-functional change
No-binary change
Infrastructure change (e.g. unit tests, helper scripts)
Automated test(s) verify changes (e.g. unit test, autotest)
Tested manually, description below (e.g. SITL)
Tested on hardware
Logs attached
Logs available on request
The old and new loops were compared on the host with 2 million generated frames, with ARM shift semantics for the old one. The results are the same except for the overshooting frames, which the old loop decoded and the new one rejects.
A full buffer of equal samples made the old loop read
buffer[23]of a 22-element buffer; the new loop stays in range.Builds for iomcu-f103-dshot.
Not tested on hardware.
Description
This PR was prepared with AI assistance (Claude Code) and checked by me.